<template>
  <div>
    <van-search
    v-model="value"
      show-action
      input-align='center'
      placeholder="请输入小区或地址"
      @search="onSearch"
    >
      <template #action>
        <div @click="$router.push('/gorent')">取消</div>
      </template>
    </van-search>

    <!-- 搜索结果 -->
    <van-cell-group v-for="(item, index) in list" :key="index">
      <van-cell @click="selected(item.communityName)" :value="item.communityName" />
    </van-cell-group>
  </div>
</template>

<script>
import { getCommunityByName } from '@/api/rent'
import { getCityValueToken } from '@/utils/storage'
export default {
  data () {
    return {
      value: '',
      list: [],
      community: ''
    }
  },
  methods: {
    async onSearch (val) {
      const { body } = await getCommunityByName({
        name: val,
        id: getCityValueToken()
      })
      console.log(body, 111)
      this.list = body
      this.community = body[0].community
      console.log(this.community)
    },
    selected (val) {
      // this.$router.push(`/rent?communityName=${val}&community=${this.community}`)
      // console.log(this.community)s
      this.$router.push({
        path: '/gorent',
        query: {
          communityName: val,
          community: this.community
        }
      })
    }
  }
}
</script>

<style></style>
